<?php
namespace Home\Controller;
use Think\Controller;

class BBScommentController extends Controller
{
	//添加评论
	public function BSScomment()
	{
		$com = M('comment');

		if(empty($_SESSION)){
			$this->error('请先登录');
		}

		$_POST['uid'] = $_SESSION['uid'];
		$_POST['username'] = $_SESSION['username'];
		$_POST['ctime'] = time();

		//初始化数据
		if(!$com->create()){
			$this->error($this->_model->getError());
			exit;
		}
		
		//执行添加
		if($com->add()>0){
			$this->success("添加成功!");
		}else{
			$this->error("添加失败");
		}
	}

	//插入回复
	public function BBSinvitReAdd()
	{
		$rep = M('replay');
		if(empty($_SESSION)){
			$this->ajaxReturn('1');
		}else{

			$_POST['rtime'] = time();
			$_POST['uid'] = $_SESSION['uid'];
			$_POST['username'] = $_SESSION['username'];
		
			//初始化数据
			if(!$rep->create()){

				$this->error($this->_model->getError());
				exit;
			}
		
			//执行添加
			if($rep->add()>0){
				$this->ajaxReturn($_POST);
				$this->success("添加成功!");
			}else{
				$this->error("添加失败");
			}

		}
		
	}
	//删除回复
	public function BBSinvitReDel()
	{
		$rep = M('replay');
		$map['rid'] = array('eq',I('get.rid'));
		if(I('get.rid')){
			$rep->where($map)->delete();
		}
	}

	//删除评论
	public function BBScommentDel()
	{
		$com = M('comment');
		$rep = M('replay');
		$map['cid'] = array('eq',I('get.cid'));
		if(I('get.cid')){
			$com->where($map)->delete();
			//并删除此评论下的所有回复
			$rep->where($map)->delete();
		}
		
	}



}